/**
 * 系统用户
 */
import { IsNotEmpty, IsString, Length } from "class-validator";
import { BaseEntity } from "../BaseEntity";
import { TStatus } from "../../types/CommonType";

import {
  BelongsToManyAddAssociationMixin,
  BelongsToManyGetAssociationsMixin,
  BelongsToManySetAssociationsMixin,
  Model,
} from "sequelize";
import { IRoleModel } from "./SysRoleEntity";

export default class SysUserEntity extends BaseEntity {
  [x: string]: any;
  id?: string;

  @Length(2, 10)
  @IsString()
  @IsNotEmpty()
  public nickname: string;

  @Length(3, 10)
  @IsString()
  @IsNotEmpty()
  public loginId: string;

  @Length(4, 1000)
  @IsString()
  @IsNotEmpty()
  public loginPwd: string;

  @IsString()
  public userType: string;

  @IsString()
  public email: string;

  @IsString()
  public phone: string;

  @IsString()
  public sex: string;

  @IsString()
  public avatar: string;

  @IsString()
  @IsNotEmpty()
  public status: TStatus;

  @IsString()
  public roleIds: string;

  public static transform(plainObject: object): SysUserEntity {
    return super.baseTransform(SysUserEntity, plainObject);
  }
}

export interface IUserModel extends Model<SysUserEntity> {
  getRole: BelongsToManyGetAssociationsMixin<IRoleModel>;
  setRole: BelongsToManySetAssociationsMixin<IRoleModel, "id">;
  addRole: BelongsToManyAddAssociationMixin<IRoleModel, "id">;
}
